home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT11 / CURS6-7.ASM next >
Encoding:
Assembly Source File  |  1993-05-10  |  4.5 KB  |  91 lines

  1. ;       Program Curs6-7 ( Chapter 11 )
  2. ;
  3.     page    55,132
  4. NewFunc equ     0E0h
  5. CheckIn equ     51h                     ; subfunction "check installation"
  6. _Text   segment para public 'CODE'
  7.     assume  cs:_Text
  8. ;=====================  Resident code ====================================
  9. Handler proc    near                    ; additional handler for interrupt 10h
  10.     cmp     ah,NewFunc              ; additional function of INT 10h?
  11.     je      Addf                    ; new handler for that function
  12.     cmp     ah,1                    ; is it function "Set Cursor Type"?
  13.     jne     ToOld10                 ; if not call standard handler
  14.     cmp     ch,cl                   ; compare first and last lines
  15.     ja      ToOld10                 ; if first > last, proceed to old
  16.     cmp     cl,7                    ; last line greater than 7?
  17.     jna     ToOld10                 ; not, proceed to old handler
  18.     mov     cl,7                    ; force last line to be 7
  19.     shr     ch,1                    ; divide first line number by 2
  20. ;===    Pass control to the standard handler of the interrupt 10h       
  21. ToOld10:jmp     dword ptr OldHand
  22. OldHand dw      ?,?
  23. OldOff  equ     OldHand[+0]
  24. OldSeg  equ     OldHand[+2]
  25. ;===    Process additional function of interrupt 10h
  26. Addf:   cmp     al,CheckIn              ; is installation check required?
  27.     jne     ToOld10
  28. Inst:   xchg    ah,al                   ; value to be returned into AX
  29.     iret                            ; return from handler   
  30. Handler endp
  31. ;===    Installation part of the program
  32. BegInst label   byte
  33. ComSeg  dw      ?
  34. PSPAddr dw      ?
  35. ;===    Installation part of the program   ===
  36. Start:  mov     PSPAddr,es              ; save address of PSP
  37.     mov     sp,0F000h               ; set the stack
  38. ;===    Free the environment memory block
  39.     mov     es,es:[2Ch]             ; address of environment block into ES 
  40.     mov     ah,49h                  ; function 49h - free memory block
  41.     int     21h                     ; DOS service call
  42. ;===
  43.     mov     es,PspAddr              ; set ES to point to PSP
  44.     mov     ComSeg,cs               ; save current command segment
  45.     mov     ds,ComSeg               ; DS = CS - data and code are the same 
  46. ;===    check whether the program is alrady installed
  47.     mov     ah,NewFunc              ; new funtion of INT 10h
  48.     mov     al,CheckIn              ; AL - installation check
  49.     int     10h                     ; call interrupt 10h - timer tick
  50.     cmp     ah,Checkin              ; does AH contain function number?
  51.     je      Already                 ; if YES, handler is already installed
  52. ;===    modifying IVT
  53.     mov     ax,3510h                ; function 35h - Get Interrupt Vector
  54.     int     21h                     ; DOS service call
  55.     mov     OldOff,bx               ; save offsett of old handler for 10h
  56.     mov     OldSeg,es               ; save segment of old handler for 10h
  57.     mov     dx,offset Handler       ; address of handler
  58.     mov     ax,2510h                ; function 25h - Set new handler
  59.     int     21h                     ; DOS service call
  60. ;===    output the message "program is installed"
  61.     lea     dx,BegMsg               ; DX - address of message
  62.     mov     ah,09h                  ; function 09 - output string
  63.     int     21h                     ; DOS service call
  64. ;===    calculate the size of the resident part 
  65.     lea     dx,BegInst
  66.     add     dx,110h                 ; PSP length plus 16 byte (insurance) 
  67.     mov     cx,4                    ; set counter for shift
  68.     shr     dx,cl                   ; 4 bits to the right - divide by 16
  69.     mov     ax,3100h                ; 31h - terminate and state resident
  70.     int     21h                     ; DOS service call
  71. ;===    Normal exit from program (return code 0)
  72. NormEx: mov     al,0                    ; return code into AL
  73. FullEx: mov     ah,4Ch                  ; function 4Ch - terminate process
  74.     int     21h                     ; DOS service call
  75. ;===    Process situation "Resident part is already installed"
  76. Already:mov     ah,09h                  ; function 09 - output text string
  77.     lea     dx,AlrMsg
  78.     int     21h                     ; DOS service call
  79.     mov     al,1
  80.     jmp     FullEx
  81. ;===    Data for non-resident part of the program
  82. CR      equ     0Ah
  83. LF      equ     0Dh
  84. EndMsg  equ     24h 
  85. BegMsg  db      CR,LF,'      The resident CGA-compatible cursor keeper.       '
  86.     db      CR,LF,'Copyright (C) 1992 V.B.Maljugin,    Russia,    Voronezh'
  87. CRLF    db      CR,LF,EndMsg
  88. AlrMsg  db      CR,LF,'Program has been already installed!',CR,LF,EndMsg
  89. _text   ends
  90.     end     Start
  91.